package ar.edu.unlp.info.cdiv;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SystemPropertiesLoader implements ServletContextListener{

	private static final String DSSD_PROPERTIES_LOCATION = "webp.properties";
	private ServletContextEvent servlet =null;
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		this.servlet = sce;
		Properties properties = new Properties();
		try {	
			URL res2 = getClass().getClassLoader().getResource(DSSD_PROPERTIES_LOCATION);
			properties.load(res2.openStream());
			for (Object key : properties.keySet()){
				System.setProperty(key.toString(),properties.getProperty(key.toString().trim()));
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		
	}

	

//	﻿@Override
//	﻿public void contextInitialized(ServletContextEvent arg0){
//	﻿﻿this.servlet=arg0;
//	﻿﻿String location=System.getenv(DSSD_PROPERTIES_LOCATION);
//	﻿﻿if(location != null){
//		﻿﻿﻿Properties properties=new Properties();
//		﻿﻿﻿try{
//			﻿﻿﻿﻿properties.load(new FileInputStream(new File(location)));
//		﻿﻿﻿}catch(FileNotFoundException e){
//			﻿﻿﻿﻿//TODOAuto-generatedcatchblock
//			﻿﻿﻿﻿e.printStackTrace();
//		﻿﻿﻿}catch(IOException e){
//		﻿﻿﻿﻿	//TODOAuto-generatedcatchblock
//		﻿﻿﻿﻿	e.printStackTrace();
//		﻿﻿﻿}
//	﻿﻿﻿for(Object key:properties.keySet()){
//	﻿﻿﻿﻿System.setProperty(key.toString(),properties.getProperty(key.toString().trim()));
//	﻿﻿﻿}
//	﻿﻿}
//	
//	﻿}
//	}
}